package com.sly.fuxi.demo.config;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 自定义拒绝策略，如果没有空闲就等待
 *
 * @author SLY
 * @date 2025/3/3
 */
public class WaitingRejectedExecutionHandler implements RejectedExecutionHandler {
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        try {
            // 当队列满时，将任务放入队列，若队列已满则阻塞等待
            executor.getQueue().put(r);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}
